<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
include '../connection/connection.php';	
$value = getlang();
include($value);

if ( !isset($_GET['pages'] ))
	{
    	$page = 1 ;
	}else{
		$page = $_GET['pages'] ;
}
	//$datecurrent = date("Y-m-d");
	$list=$_SESSION['sort'];
//	$page=$_GET['pages'];
	$str=$_GET['str'];
	$_SESSION['sortn']=$str;
	$flagDesc=$_GET['flagDesc'];
	
	$search=$_REQUEST['search'];
	$from=$_REQUEST['from'];
	$to=$_REQUEST['to'];
	$lstatus=$_REQUEST['status'];
	$oneday=$_REQUEST['searchOneDay'];
	$twodays=$_REQUEST['twodays'];
	$oneweek=$_REQUEST['oneweek'];
	$onemonth=$_REQUEST['onemonth'];
	
	$rows_per_page = 20 ;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	if(!isset($_REQUEST['page'])){
		$list["ui.email"]="DESC";
		$list["lvs.viewer_ip"]="DESC";
		$list["lvs.server_ip"]="DESC";
		$list["lvs.status"]="DESC";
		$list["lvs.ins_time"]="DESC";
		
		$str="lvs.ins_time";
		$_SESSION['sortn']=$str;
		$_SESSION['sort']=$list;
	}else{
		$str=$_SESSION['sortn'];
		$list=$_SESSION['sort'];
	}
	if($flagDesc==1){

		if($list[$str]=="DESC")
			$list[$str]="ASC";
		else
			$list[$str]="DESC";
	}
	
	$sql = "SELECT lvs.*,ui.email FROM `user_info` ui, log_viewer_to_server lvs WHERE lvs.id = ui.id ";
	
	$selectlogserver = mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
	$number_of_page = ceil ( mysql_num_rows( $selectlogserver ) / $rows_per_page );

	$_SESSION['sort']=$list;
?>
<thead>
			<tr>
					<td align="center" style="color: #696969;width: 4%"><?php echo $no?></td>
					<td align="center"><a onclick="sortandpagingAllViewertoServer('<?=$page?>','ui.email',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')" style="cursor: pointer;color: #027acc"><?php echo $useriforid ?></a></td>
					<td align="center"><a onclick="sortandpagingAllViewertoServer('<?=$page?>','lvs.viewer_ip',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewip ?></a></td>
					<td align="center"><a onclick="sortandpagingAllViewertoServer('<?=$page?>','lvs.server_ip',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteserverip?></a></td>
					<td align="center"><a onclick="sortandpagingAllViewertoServer('<?=$page?>','lvs.status',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')" style="cursor: pointer;color: #027acc"><?php echo $status?></a></td>
					<td align="center"><a onclick="sortandpagingAllViewertoServer('<?=$page?>','lvs.ins_time',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')" style="cursor: pointer;color: #027acc"><?php echo $inserttime?></a></td>
				</tr>
		</thead>
			<?php
			if(mysql_num_rows($selectlogserver)>0){
				$i=0;
				while ($row = mysql_fetch_array($selectlogserver)){
					if ( $i >= $page_start ){?>
				<tr>
						<td align="center" style="width: 4%;background: white;color: #5D5D5D;font-weight: normal;"><?php echo $i+1?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[email] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[viewer_ip] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_ip]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[status]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[ins_time]?></td>
					</tr>
			<?php
					}
						$i++;
						if ($i >= $page_end){
							break;
						}
					}
				}
			?>
			
			<tr>
						<td colspan="8" class="rf-dt-shdr-c">
							<span style="padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="sortandpagingAllViewertoServer(<?=1?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')"><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="sortandpagingAllViewertoServer(<?=($page-1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')"><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{
										echo "<span class='button_next'><<<</span> "; 
										echo "<span class='button_next'><<</span> ";
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="sortandpagingAllViewertoServer(<?=$i?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')"><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="sortandpagingAllViewertoServer(<?=($page+1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="sortandpagingAllViewertoServer(<?=($number_of_page)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>')"><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>